package controllers;

import play.*;
import play.db.ebean.Transactional;
import play.mvc.*;
import views.html.*;
import models.*;
import static play.data.Form.*;
import play.data.Form;
import java.util.List;

public class Application extends Controller {

    public static Result index() {
        return ok(index.render("Football"));
    }

    @Transactional
    public static Result handle() {
        Form<Player> playerForm = form(Player.class).bindFromRequest();
        if(playerForm.hasErrors()) {
            return badRequest(errorPage.render(playerForm));
        }
        playerForm.get().save();
        List<Player> players = Player.find.where().orderBy("playerId DESC").setMaxRows(1).findList();
        Player player = players.get(0);
        return ok(handlePage.render(player.name, player.accuratePasses, player.goals));
    }

}
